#include <cassert>
#include <panel.h>
#include <cdk/cdk.h>
#include "window.h"
#include "_window.h"
#include "terminal.h"
#include "editbox.h"

Factory<Window> Window::create;

Window::Window(const int& top, const int& left,
const int& height, const int& width) : p(new P) {
  p->window_ =newwin(top, left, height, width);
  assert(p->window_ != NULL);

  p->panel_ =new_panel(p->window_);
  assert(p->panel_ != NULL);

  p->cdk_ =initCDKScreen(p->window_);
  assert(p->cdk_ != NULL);
}

Window::Window() : Window(0, 0, 0, 0) {
}

Window::~Window() {
}

Window& Window::height(const int& rows) {
  wresize(p->window_, rows, width());
  return *this;
}

Window& Window::width(const int& cols) {
  wresize(p->window_, width(), cols);
  return *this;
}

Window& Window::size(const int& rows, const int& cols) {
  wresize(p->window_, rows, cols);
  return *this;
}

int Window::height() const {
  int rows, cols;
  getbegyx(p->window_, rows, cols);
  return rows;
}

int Window::width() const {
  int rows, cols;
  getbegyx(p->window_, rows, cols);
  return cols;
}

Window& Window::show() {
  show_panel(p->panel_);
  return *this;
}

Window& Window::hide() {
  hide_panel(p->panel_);
  return *this;
}

bool Window::hidden() const {
  return panel_hidden(p->panel_) == TRUE;
}

bool Window::visible() const {
  return !hidden();
}

Window& Window::clear() {
  eraseCDKScreen(p->cdk_);
  return *this;
}

int Window::getch() const {
  return wgetch(p->window_);
}


